angular.module('service.advertisement', [
        'ngResource'
    ])
    .service('AdvertisementService', AdvertisementService);
AdvertisementService.$inject = ['$resource'];
function AdvertisementService($resource) {

    // 通过店铺id获取订单
    this.getadv = function (shopid, astate) {
        var resource = $resource(adv_url + "order/time/:shopid");
        return resource.query({shopid: shopid, astate: astate});
    };

    // 通过广告id获取订单
    this.getById = function (adid) {
        var resource = $resource(adv_url + "order/adid/:adid");
        return resource.query({adid: adid});
    };

    // 通过广告id获取广告
    this.advert = function (adid) {
        var resource = $resource(adv_url + "advert/:adid");
        return resource.get({adid: adid});
    };

    // 取消店铺广告绑定
    this.cancelBinding = function (adid, shopid) {
        var resource = $resource(adv_url + "binding/testcancel/" + adid + "?shopid=" + shopid);
        return resource.save();
    };

    this.shopUnusual = function (info) {
        var resource = $resource(adv_url + "shopunusual");
        return resource.save(info)
    };

    // 添加异常广告内容
    this.addAdvert = function (info) {
        var resource = $resource(adv_url + "advert");
        return resource.save(info);
    };

    // 根据广告id获取广告绑定信息
    this.getBinding = function (adid) {
        var resource = $resource(adv_url + "binding/adid/" + adid);
        return resource.query();
    };

    // 根据广告id和门店id修改绑定信息
    this.updateUnusual = function (adid, shopid, unusualid) {
        var resource = $resource(adv_url + "shopunusual/updatebykey/" + adid + "?shopid=" + shopid + "&unusualid=" + unusualid);
        return resource.save();
    };

    // 根据状态和门店获取广告信息
    this.getAdvByShopId = function (id, state) {
        var resource = $resource(adv_url + "binding/shopid/" + id + "?state=" + state);
        return resource.query({}, {id: id, state: state});
    }
}